package gtdz.algo.rk4;

import com.sun.javafx.geom.Point2D;

public class U  {
	private final double[] values;
	
	
	public U (double x, double y, double vx, double vy) {
		super();
		values = new double[4];
		values[0] = x;
		values[1] = y;
		values[2] = vx;
		values[3] = vy;
	}
	
	private U(double[] values) {
		super();
		this.values = values;
	}

	
	public double getX() {
		return values[0];
	}

	public double getY() {
		return values[1];
	}
	
	public double getVx() {
		return values[2];
	}

	public double getVy() {
		return values[3];
	}	
	
	public Point2D getPoint() {
		//The first two elements of u are (x, y) by convention.
		return new Point2D((float) values[0], (float) values[1]);
	}
	
	public U mul(double m) {
		double[] result = new double[values.length];
		for (int i = 0; i < result.length; i++) {
			result[i] = values[i] * m; 
		}
		return new U(result);
	}
	
	public U add(U in) {
		double[] result = new double[values.length];
		for (int i = 0; i < result.length; i++) {
			result[i] = values[i] + in.values[i]; 
		}
		return new U(result);
	}

}
